package com.ctshk.sapp.workflow.controller;


import com.ctshk.common.annotations.OperationLogAnnotation;
import com.ctshk.common.dto.Result;
import com.ctshk.common.enums.OperationLogModel;
import com.ctshk.common.enums.OperationLogType;
import com.ctshk.common.model.PageResponse;
import com.ctshk.rpc.workflow.dto.ApprovalSettingInfoDTO;
import com.ctshk.rpc.workflow.dto.ApprovalSettingListDTO;
import com.ctshk.rpc.workflow.req.ApprovalSettingQueryReq;
import com.ctshk.rpc.workflow.req.ApprovalSettingReq;
import com.ctshk.rpc.workflow.service.ISysApprovalSettingService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.apache.dubbo.config.annotation.DubboReference;
import org.springframework.web.bind.annotation.*;

import com.ctshk.common.web.support.BaseController;

import javax.validation.Valid;

/**
 * <p>
 * 审批模板配置表 前端控制器
 * </p>
 *
 * @author 谢诗宏
 * @since 2021-01-25
 */
@Api(value="审批", tags="审批模板管理")
@RestController
@RequestMapping("/approval/template")
public class SysApprovalSettingController extends BaseController {

    @DubboReference
    private ISysApprovalSettingService approvalSettingService;

    @ApiOperation(value="新增审批流程", notes="新增审批流程模板")
    @OperationLogAnnotation(operModul = OperationLogModel.APPROVAL, operType = OperationLogType.ADD, operTitle = "新增审批流程", operDesc = "新增审批流程模板")
    @PostMapping("/add")
    public Result add(@RequestBody @Valid ApprovalSettingReq settingReq) {
        return Result.success(approvalSettingService.add(settingReq, super.getCurrentUser(getRequest()).getId()));
    }

    @ApiOperation(value="编辑审批流程", notes="编辑审批流程模板")
    @OperationLogAnnotation(operModul = OperationLogModel.APPROVAL, operType = OperationLogType.UPDATE, operTitle = "编辑审批流程", operDesc = "'编辑审批流程模板' + #settingReq.id")
    @PostMapping("/edit")
    public Result update(@RequestBody @Valid ApprovalSettingReq settingReq) {
        return Result.success(approvalSettingService.update(settingReq, super.getCurrentUser(getRequest()).getId()));
    }

    @ApiOperation(value="删除审批模板", notes="删除审批模板")
    @OperationLogAnnotation(operModul = OperationLogModel.APPROVAL, operType = OperationLogType.DELETE, operTitle = "删除审批模板", operDesc = "删除审批模板")
    @GetMapping("/del/{id}")
    public Result del(@PathVariable Long id) {
        return Result.success(approvalSettingService.del(id, getCurrentUser(getRequest()).getId()));
    }

    @ApiOperation(value="查询审批模板详情", notes="查询审批模板详情")
    @OperationLogAnnotation(operModul = OperationLogModel.APPROVAL, operType = OperationLogType.QUERY, operTitle = "查询审批模板详情", operDesc = "查询审批模板详情")
    @GetMapping("/info/{id}")
    public Result<ApprovalSettingInfoDTO> query(@PathVariable Long id) {
        return Result.success(approvalSettingService.query(id));
    }

    @ApiOperation(value="查询审批模板列表", notes="查询审批模板列表")
    @OperationLogAnnotation(operModul = OperationLogModel.APPROVAL, operType = OperationLogType.QUERY, operTitle = "查询审批模板列表", operDesc = "查询审批模板列表")
    @PostMapping("/list")
    public Result<PageResponse<ApprovalSettingListDTO>> list(@RequestBody ApprovalSettingQueryReq settingQueryReq) {
        return Result.success(approvalSettingService.getList(settingQueryReq));
    }

    @ApiOperation(value="复制审批模板", notes="复制审批模板")
    @OperationLogAnnotation(operModul = OperationLogModel.APPROVAL, operType = OperationLogType.QUERY, operTitle = "复制审批模板", operDesc = "复制审批模板")
    @GetMapping("/copy/{id}")
    public Result copy(@PathVariable Long id) {
        return Result.success(approvalSettingService.copy(id, getCurrentUser(getRequest()).getId()));
    }

}
